<?php
/**
 * Created by PhpStorm.
 * User: SnGef
 * Date: 2017/6/26
 * Time: 18:35
 */
global $_W, $_GPC;

$pageid = empty($_GPC['pageid']) ? "" : $_GPC['pageid'];

$page     = intval(trim($_GPC['page'])) ?: '';
$pindex   = max(1, intval($page));
$psize    = 20;
$kw       = empty($_GPC['keyword']) ? "" : $_GPC['keyword'];
$deviceUseList    = pdo_fetchall(@"
SELECT a.*,b.device_name,b.`key`,c.nickname ,b.batch_number
FROM " . tablename('xd_device_use_record') . " a
LEFT JOIN " . tablename('xd_device') . " b ON a.device_id=b.id
LEFT JOIN " . tablename('mc_mapping_fans') . " c ON a.uid=c.fanid 
WHERE  b.device_name LIKE :name 
ORDER BY a.id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize,
    array(
    ':name' => "%{$kw}%"
    )
);

$pagesnum = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('xd_device_use_record'));
$total    = pdo_fetchcolumn(@"SELECT a.*,b.device_name,b.`key`,c.nickname ,b.batch_number
FROM " . tablename('xd_device_use_record') . " a
LEFT JOIN " . tablename('xd_device') . " b ON a.device_id=b.id
LEFT JOIN " . tablename('mc_mapping_fans') . " c ON a.uid=c.fanid 
WHERE  b.device_name LIKE :name 
ORDER BY a.id DESC",
    array(
    ':name' => "%{$kw}%"
    )
);

$pager    = pagination($total, $pindex, $psize);
//print_r($_W['uniacid']);exit;
include $this->template('device_use_record_list');